package dongchel.vrp.immunes;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import dongchel.vrp.entity.City;
import dongchel.vrp.entity.Solution;
import dongchel.vrp.view.ShowSolution;


public class Mutation {
	private List<Solution> population;	

	private List<Solution> mutatedPopulation = new ArrayList<Solution>();
	
	private List<Double> affinity;
	public Mutation(List<Solution> population, List<Double> affinity){
		this.population = population;
		this.affinity = affinity;
	}
	
	public void mutate(Solution solution) {
		int pattern = (int)Math.round(Math.random());
		LocalSearch lS = new LocalSearch();
		if (pattern ==0) {
			int patt = (int)Math.floor(Math.random()*4)+1;
			lS.intraRouteMove(solution, patt);
		}
		else {
			int patt = (int)Math.floor(Math.random()*6)+1;
			lS.interRouteMove(solution, patt);
		}

	}
	
	public void hypermutatePopulation() {
		//firstly clone solutions in population to mutatedPopulation
		for(int i=0;i<population.size();i++) {
			mutatedPopulation.add((Solution)population.get(i).clone());
		}		
		//then mutate according to affinity  
		for(int i=0;i<mutatedPopulation.size();i++) {
			//for(int j=0;j<Math.round(affinity.get(i)*mutatedPopulation.size()*5+i+1);j++) {
				mutate(mutatedPopulation.get(i));			
			//}		
		}	
	}

	public List<Solution> getMutatedPopulation() {
		return mutatedPopulation;
	}

	public void setMutatedPopulation(List<Solution> mutatedPopulation) {
		this.mutatedPopulation = mutatedPopulation;
	}
}
